package com.xiangjun.proxytest.jdkdynamicproxytest;

import com.xiangjun.proxytest.jdkdynamicproxytest.impl.HttpsOrigin;
import com.xiangjun.proxytest.jdkdynamicproxytest.impl.JDKDynamicProxyFactory;

import java.lang.reflect.Proxy;

public class test {
    public static void main(String[] args) {

        ////先new一个需要被代理的类
        //HttpOrigin httpOrigin = new HttpOrigin();
        ////获取动态代理工厂类，将需要被代理的类放进去
        //JDKDynamicProxyFactory jdkDynamicProxyFactory = new JDKDynamicProxyFactory(httpOrigin);
        //
        ////获取代理对象，newProxyInstance方法有三个入参：1、被代理的类的类装载器，2、被代理类的接口信息，3、动态代理工厂类
        ////该方法的返参必须是由被代理类的接口来接受，使用了类的多态性。也进一步的体现了JDK代理基于接口实现的特性
        //HttpOriginInterface httpOriginProxy = (HttpOriginInterface) Proxy.newProxyInstance(httpOrigin.getClass().getClassLoader(),
        //        httpOrigin.getClass().getInterfaces(),jdkDynamicProxyFactory);
        //httpOriginProxy.get("get请求");
        //httpOriginProxy.post("post请求");


        HttpsOrigin httpsOrigin = new HttpsOrigin();
        JDKDynamicProxyFactory jdkDynamicProxyFactory1 = new JDKDynamicProxyFactory(httpsOrigin);
        HttpsOriginInterface httpsExecute = (HttpsOriginInterface) Proxy.newProxyInstance(httpsOrigin.getClass().getClassLoader(),
                httpsOrigin.getClass().getInterfaces(),jdkDynamicProxyFactory1);

        httpsExecute.httpsGet();
        httpsExecute.httpsPost();


    }
}
